package com.qj.daibei.controller;

import com.qj.daibei.pojo.City;
import com.qj.daibei.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * author wml
 * Created on 2021/9/24 15:05
 */
@Controller
public class CityController {

    @Autowired
    private CityService cityService;

    /**
     * 查询所有的城市
     * @Author wml
     * @return 返回一个 JSON 格式的城市集合
     */
    @GetMapping("/ajaxGetCity")
    public ResponseEntity<List<City>> ajaxGetCity() {
        List<City> cityList = this.cityService.queryAllCity();
        return new ResponseEntity<List<City>>(cityList, HttpStatus.OK);
    }

    /**
     * 接收前端传来的省份 id，查询这个省份下的所有城市
     * @Author wml
     * @param proId
     * @return 返回一个 JSON 格式的城市集合
     */
    @GetMapping("/ajaxGetCityByProId")
    public ResponseEntity<List<City>> ajaxGetCityByProId(String proId) {
        List<City> cityList = this.cityService.queryCityByProId(proId);
        return new ResponseEntity<List<City>>(cityList, HttpStatus.OK);
    }
}
